<html>
<head><meta charset="utf-8"><title>Opt-out blanket impls · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Opt-out.20blanket.20impls.html">Opt-out blanket impls</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="201910475"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Opt-out%20blanket%20impls/near/201910475" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> alercah <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Opt-out.20blanket.20impls.html#201910475">(Jun 24 2020 at 22:16)</a>:</h4>
<p>Is there any work done on opt-out blanket impls, by which I mean a generic impl in a crate that defines a trait, where a crate defining a type could define a local impl for the same trait that would supplant the generic one, rather than being a coherence violation? Is there any conceptual barrier to that?</p>
<p>Asking because I'm writing a reply on the IndexGet/DerefMove thread and I'm realizing I really want it.</p>



<a name="201910886"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Opt-out%20blanket%20impls/near/201910886" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> alercah <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Opt-out.20blanket.20impls.html#201910886">(Jun 24 2020 at 22:22)</a>:</h4>
<p>(In this specific case, we can get around it because we're talking about operators, so the compiler could do the fallback work in the language, but that's far less clean I think.)</p>



<a name="201911090"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Opt-out%20blanket%20impls/near/201911090" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> alercah <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Opt-out.20blanket.20impls.html#201911090">(Jun 24 2020 at 22:25)</a>:</h4>
<p>I guess this is really a particular case of specialization, I'll poke at that.</p>



<a name="201911268"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Opt-out%20blanket%20impls/near/201911268" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> alercah <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Opt-out.20blanket.20impls.html#201911268">(Jun 24 2020 at 22:27)</a>:</h4>
<p>Wait... for some reason I thought that specialization as it was proposed still required each leaf impl to be declared separately. I think I can safely be ignored, then.</p>



<a name="201912477"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Opt-out%20blanket%20impls/near/201912477" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> alercah <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Opt-out.20blanket.20impls.html#201912477">(Jun 24 2020 at 22:40)</a>:</h4>
<p>I'll just mosey on back out :P</p>



<a name="201922995"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Opt-out%20blanket%20impls/near/201922995" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Opt-out.20blanket.20impls.html#201922995">(Jun 25 2020 at 01:16)</a>:</h4>
<p>This sounds like specialization to me</p>



<a name="202015619"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Opt-out%20blanket%20impls/near/202015619" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> alercah <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Opt-out.20blanket.20impls.html#202015619">(Jun 25 2020 at 19:42)</a>:</h4>
<p>Okay, actual question though: is there any way to make blanket impl that can be <em>opted out of</em> rather than implemented differently.</p>
<p>Ignoring bikeshed syntax, this would mean that <code>opt_out impl&lt;T&gt; Trait for T</code> couldn't even be used in a generic context where you just have <code>T</code>.</p>



<a name="202015665"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Opt-out%20blanket%20impls/near/202015665" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> alercah <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Opt-out.20blanket.20impls.html#202015665">(Jun 25 2020 at 19:43)</a>:</h4>
<p>Looking for ways that <code>m[k] = v;</code> could work and <code>m[&amp;k] = v;</code> could fail without breaking indexed assignment for existing <code>IndexMut</code> users.</p>



<a name="202611466"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Opt-out%20blanket%20impls/near/202611466" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Opt-out.20blanket.20impls.html#202611466">(Jul 01 2020 at 19:13)</a>:</h4>
<p>Your new (actual) question sounds like negative impls?</p>



<a name="203301498"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Opt-out%20blanket%20impls/near/203301498" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Opt-out.20blanket.20impls.html#203301498">(Jul 08 2020 at 18:04)</a>:</h4>
<p>I've pondered before about whether there's a version of negative bounds that wouldn't be a hazard, perhaps by saying that you can have an impl with a negative bound only when there's also an impl for the equivalent but with a positive bound.  That would allow one for <code>: Copy</code> and one for <code>: Clone + !Copy</code>, for example, which might hit many of the places it was desired.</p>



<a name="203307766"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Opt-out%20blanket%20impls/near/203307766" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Barsky <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Opt-out.20blanket.20impls.html#203307766">(Jul 08 2020 at 18:57)</a>:</h4>
<p>(long-time reader, first-time caller)</p>
<p>that would probably solve a lot of cases where I wanted negative bounds; it was almost always express a fully disjoint calling pattern</p>



<a name="203325941"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Opt-out%20blanket%20impls/near/203325941" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Opt-out.20blanket.20impls.html#203325941">(Jul 08 2020 at 21:28)</a>:</h4>
<p><span class="user-mention" data-user-id="125270">@scottmcm</span> there is a version of negative that works ok, I think, but it involves something like this:</p>



<a name="203325963"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Opt-out%20blanket%20impls/near/203325963" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Opt-out.20blanket.20impls.html#203325963">(Jul 08 2020 at 21:29)</a>:</h4>
<p>for each trait <code>Foo</code>, you can imagine there is an "anti-trait" called <code>!Foo</code></p>



<a name="203325993"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Opt-out%20blanket%20impls/near/203325993" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Opt-out.20blanket.20impls.html#203325993">(Jul 08 2020 at 21:29)</a>:</h4>
<p>coherence guarantees that the impls of <code>Foo</code> and <code>!Foo</code> do not overlap</p>



<a name="203326012"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Opt-out%20blanket%20impls/near/203326012" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Opt-out.20blanket.20impls.html#203326012">(Jul 08 2020 at 21:29)</a>:</h4>
<p>(in the same way that it guarantees distinct impls of <code>Foo</code> don't overlap)</p>



<a name="203326048"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Opt-out%20blanket%20impls/near/203326048" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Opt-out.20blanket.20impls.html#203326048">(Jul 08 2020 at 21:29)</a>:</h4>
<p>now you can write <code>T: Foo</code> and <code>T: !Foo</code> and they are both fine -- basically, proving <code>T: !Foo</code> involves searching for an applicable impl of <code>!Foo</code></p>



<a name="203326104"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Opt-out%20blanket%20impls/near/203326104" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Opt-out.20blanket.20impls.html#203326104">(Jul 08 2020 at 21:30)</a>:</h4>
<p>this <em>doesn't</em> incorporate the idea of "you get to assume your crate-local types do not implement things"</p>



<a name="203326119"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Opt-out%20blanket%20impls/near/203326119" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Opt-out.20blanket.20impls.html#203326119">(Jul 08 2020 at 21:30)</a>:</h4>
<p>and we'd also maybe want to extend coherence to understand that <code>T: Copy</code> and <code>T: !Copy</code> are mutually incompaible</p>



<a name="203326148"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Opt-out%20blanket%20impls/near/203326148" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Opt-out.20blanket.20impls.html#203326148">(Jul 08 2020 at 21:30)</a>:</h4>
<p>but it avoids some of the hazards of adding negative goals that we have to prove, because we'r enot really proving negative goals</p>



<a name="203326162"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Opt-out%20blanket%20impls/near/203326162" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Opt-out.20blanket.20impls.html#203326162">(Jul 08 2020 at 21:30)</a>:</h4>
<p>that is, we're not proving "there is no impl of <code>Foo</code>", we're proving "there is a negative impl of <code>Foo</code>"</p>



<a name="204492967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Opt-out%20blanket%20impls/near/204492967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Opt-out.20blanket.20impls.html#204492967">(Jul 20 2020 at 22:46)</a>:</h4>
<p>That makes total sense to me for allowing people to write <code>impl !Copy for String</code>, or whatever, and have things take advantage of it explicitly.  I guess my post had been more from the specialization angle rather than the disjointness angle -- not asking people to _promise_ <code>!Copy</code>, but taking advantage of <code>Copy</code>-vs-<code>!Copy</code> for different implementations in such a way that my code will continue to work regardless of whether they implement <code>Copy</code> or <code>!Copy</code> on their type that currently isn't either.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>